Create Your First Functional Component in React JS – Beginner's Guide

Image
Create Your First Functional Component in React JS  1. Introduction When you start learning React JS, one of the first things you will come across is the concept of components. At first, components may seem like just another programming concept, but they are actually the foundation of almost every React application. Think about a website you use every day. It may have a header, navigation menu, login form, product section, and footer. Instead of writing all these elements together in one large file, React allows us to create separate parts and manage them independently. These separate parts are called components. In this tutorial, we are going to create our first functional component in React. We will start with a very simple example and gradually understand how components are created, exported, imported, and displayed on a webpage.  2. What Is a Functional Component in React?   A functional component is simply a JavaScript function that returns a user interface using JSX...

How to Create Alphabet O Pattern in C Programming

How to Create Alphabet O Pattern in C Programming


C program to Print  Alphabet  O star pattern 

Example 


#include <stdio.h>

int main()
{
    int a, b;
    int n = 7; // height and width of the O

    for (a = 0; a < n; a++)
{
        for (b = 0; b < n; b++)
{
            // Print * for the boundary of O
            if ((a == 0 || a == n-1) && (b > 0 && b < n-1)
|| (b == 0 || b == n-1) && (a > 0 && a < n-1))
                printf("*");
            else
                printf(" ");
       
}

        printf("\n");

    }

    return 0;
}


This C Program Print  pattern in the shape of the capital letter O using asterisks  "*"
Explain Program

Step :1

Variable Declaration

int a, b;
int n = 7; // height and width of the O

a and b are loop variables:
a is used to track rows
b is used to track columns
n = 7 sets both the height and width of the "O". So the output will be a 7x7 grid.

Step :2

Outer Loop – Controls Rows


for (a = 0; a < n; a++)

 loop Run from a = 0 to a = 6 (7 row total).
Each iteration represents  new row.

Step :3  

Inner Loop – Controls Columns


for (b = 0; b < n; b++)

This loop run for each column in the row.
 for each row, it prints 7 characters (b = 0 to b = 6).

Step :4

 Conditional Statement use

if ((a == 0 || a == n-1) && (b > 0 && b < n-1) 
 || (b == 0 || b == n-1) && (a > 0 && a < n-1))
    printf("*");
else
    printf(" ");
Let’s break this condition down:

Step :5

First Part: 

(a== 0 || a == n-1) && (b > 0 && b < n-1)

Handles top and bottom row, but only middle part
a == 0 → first row (top of the O)
a == n-1 → last row (bottom of the O)
b > 0 && b < n-1 → avoid the corners 

Step :6

This draws the top and bottom horizontal lines of the 'O' (excluding corners).
Second Part:

 (b == 0 || b == n-1) && (a > 0 && a < n-1)

handles the left and right column, but only the middle part


b == 0 → first column (left edge)
b == n-1 → last column (right edge)
a > 0 && a < n-1 → avoid the top and bottom rows

Step :7

This draws the left and right vertical lines of the 'O' (excluding corners).
 Else Case

    printf(" ");

 condition is not met, it prints a space, so the inside of the 'O' is hollow.

Step :8

printf("\n");

After each row is completed, move to  next line.


C program to Print  Alphabet  O star pattern 

Output


C program to Print  Alphabet  O star pattern




Related Post :-

C program to print alphabet g star Pattern

C program to print alphabet f star pattern

Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

CSS Outline Offset Property with Practical Examples